package com.jeeinc.oa.config;

import javax.annotation.Resource;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.context.annotation.PropertySource;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.stereotype.Controller;

import com.jeeinc.oa.domain.Account;
import com.jeeinc.oa.service.IAccountService;
import com.jeeinc.oa.utils.StringUtils;

@Configuration
@ComponentScan(value = "com.jeeinc.oa", excludeFilters = {
		@Filter(Controller.class),
		@Filter(type = FilterType.ASSIGNABLE_TYPE, value = RootConfiguration.class) })
@PropertySource("classpath:config.properties")
@EnableScheduling
public class RootConfiguration {
	@Resource
	private IAccountService accountService;

	@Bean
	public Boolean initAdmin() {
		Account account = accountService.getAccount("admin");
		if (account == null) {
			account = new Account();
			account.setLoginname("admin");
			account.setMask(StringUtils.generateUpperString(8));
			account.setName("系统管理员");
			account.setLoginpwd(StringUtils.encryption("admin", account.getMask()));
			accountService.saveAccount(account);
		}
		return true;
	}
	
}